layui.use(['form','layer','jquery'],function(){
    var verifyCode = new GVerify("yzmContent");//初始化验证码
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer
        $ = layui.jquery;

    //登录按钮
    form.on("submit(login)",function(data){
        var autoLogin=2;//是否自动登录，2.否，1.是
        var loginId=$("#loginId").val();
        var inputPassword=$("#inputPassword").val();
        var inputYZM=$("#inputYZM").val();
        if(loginId == "" || loginId==null){
            offset("auto","请输入登录名！","登录提示","确定");
            return false;
        }
        if(inputPassword == "" || inputPassword==null){
            offset("auto","请输入密码！","登录提示","确定");
            return false;
        }
        if(inputYZM == "" || inputYZM==null){
            offset("auto","请输入验证码！","登录提示","确定");
            return false;
        }
        var res = verifyCode.validate(inputYZM);
        if(!res){
            offset("auto","验证码输入错误！","登录提示","确定");
            return false;
        }
        if($("#loginCheck").is(":checked")){
            autoLogin=1;
        }
        var url="baseUser/login";
        var params = {
            userid: loginId,
            autoLogin: autoLogin,
            userpassword:inputPassword
        };
        $(this).text("登录中...").attr("disabled","disabled").addClass("layui-disabled");
        var obj=$(this);
        $.ajax({
            url : url,
            type : 'POST',
            data : params,
            dataType : 'json',
            //contentType : 'application/json',
            success : function(data, status, xhr) {
                if(data.code=="success"){
                    location.href=data.url;
                }else {
                    obj.text("登录").removeAttr("disabled").removeClass("layui-disabled");
                    offset("auto",data.errorMsg,"登录提示","确定");
                }
            },
            Error : function(xhr, error, exception) {
                obj.text("登录").removeAttr("disabled").removeClass("layui-disabled");
                offset("auto",exception.toString(),"登录提示","确定");
            }
        });
        return false;
    })

    //表单输入效果
    $(".loginBody .input-item").click(function(e){
        e.stopPropagation();
        $(this).addClass("layui-input-focus").find(".layui-input").focus();
    })
    $(".loginBody .layui-form-item .layui-input").focus(function(){
        $(this).parent().addClass("layui-input-focus");
    })
    $(".loginBody .layui-form-item .layui-input").blur(function(){
        $(this).parent().removeClass("layui-input-focus");
        if($(this).val() != ''){
            $(this).parent().addClass("layui-input-active");
        }else{
            $(this).parent().removeClass("layui-input-active");
        }
    })
})
